home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Windows.Forms;
-
- // Die Component o5/2oo3 by stjo@borland.com
- //
- // To run this Sample :
- // 1┬░) Open Die.bdsproj and compile it to create Die.dll
- // 2┬░) Install the component (Menu Components, Installed .Net Components, Select an Assembly : Die.dll)
- // 3┬░) Open Dice.bdsproj and run it !
-
- namespace Die
- {
- /// <summary>
- /// Summary description for UserControl1.
- /// </summary>
- public class Dice : System.Windows.Forms.UserControl
- {
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- private System.Windows.Forms.PictureBox pictureBox1;
- private System.Windows.Forms.PictureBox pictureBox3;
- private System.Windows.Forms.PictureBox pictureBox4;
- private System.Windows.Forms.PictureBox pictureBox5;
- private System.Windows.Forms.PictureBox pictureBox6;
- private System.Windows.Forms.PictureBox pictureBox7;
- private System.Windows.Forms.PictureBox pictureBox9;
-
- // Specifies the random engine
- // to launch the dice
- private System.Random random;
-
- // Determines the number displayed
- // on the dice from 1 to 6
- private System.Int32 _face;
- public System.Int32 face {
- get { return _face; }
- set {
- if (value>=1 && value<=6) {
- _face=value;
- display();
- } else {
- throw new Exception("Dice must be from 1 to 6");
- }
- }
- }
-
- // Allows of not the dice to be launched
- private System.Boolean _active=true;
- public System.Boolean active {
- get { return _active; }
- set {
- _active=value;
- // And changes dice background color
- BackColor=_active?
- System.Drawing.SystemColors.ActiveCaptionText
- :System.Drawing.SystemColors.InactiveBorder;
- }
- }
-
- public void launch()
- {
- if (active) {
- // Get a random face number
- face=random.Next(6)+1;
- }
- }
-
- public void display()
- {
- // Show/Hide points
- pictureBox1.Visible=(face>1);
- pictureBox3.Visible=(face>=4);
- pictureBox4.Visible=(face==6);
- pictureBox5.Visible=(face==1 || face==3 || face==5);
- pictureBox6.Visible=(face==6);
- pictureBox7.Visible=(face>=4);
- pictureBox9.Visible=(face>1);
- }
-
- public Dice()
- {
- // This call is required by the Windows.Forms Form Designer.
- random=new System.Random();
- InitializeComponent();
- launch();
- // TODO: Add any initialization after the InitForm call
- }
-
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if( components != null )
- components.Dispose();
- }
- base.Dispose( disposing );
- }
-
- #region Component Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Dice));
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- this.pictureBox3 = new System.Windows.Forms.PictureBox();
- this.pictureBox4 = new System.Windows.Forms.PictureBox();
- this.pictureBox5 = new System.Windows.Forms.PictureBox();
- this.pictureBox6 = new System.Windows.Forms.PictureBox();
- this.pictureBox7 = new System.Windows.Forms.PictureBox();
- this.pictureBox9 = new System.Windows.Forms.PictureBox();
- this.SuspendLayout();
- //
- // pictureBox1
- //
- this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
- this.pictureBox1.Location = new System.Drawing.Point(8, 56);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(16, 16);
- this.pictureBox1.TabIndex = 0;
- this.pictureBox1.TabStop = false;
- this.pictureBox1.Visible = false;
- //
- // pictureBox3
- //
- this.pictureBox3.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox3.Image")));
- this.pictureBox3.Location = new System.Drawing.Point(56, 56);
- this.pictureBox3.Name = "pictureBox3";
- this.pictureBox3.Size = new System.Drawing.Size(16, 16);
- this.pictureBox3.TabIndex = 2;
- this.pictureBox3.TabStop = false;
- this.pictureBox3.Visible = false;
- //
- // pictureBox4
- //
- this.pictureBox4.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox4.Image")));
- this.pictureBox4.Location = new System.Drawing.Point(8, 32);
- this.pictureBox4.Name = "pictureBox4";
- this.pictureBox4.Size = new System.Drawing.Size(16, 16);
- this.pictureBox4.TabIndex = 3;
- this.pictureBox4.TabStop = false;
- this.pictureBox4.Visible = false;
- //
- // pictureBox5
- //
- this.pictureBox5.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox5.Image")));
- this.pictureBox5.Location = new System.Drawing.Point(32, 32);
- this.pictureBox5.Name = "pictureBox5";
- this.pictureBox5.Size = new System.Drawing.Size(16, 16);
- this.pictureBox5.TabIndex = 4;
- this.pictureBox5.TabStop = false;
- this.pictureBox5.Visible = false;
- //
- // pictureBox6
- //
- this.pictureBox6.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox6.Image")));
- this.pictureBox6.Location = new System.Drawing.Point(56, 32);
- this.pictureBox6.Name = "pictureBox6";
- this.pictureBox6.Size = new System.Drawing.Size(16, 16);
- this.pictureBox6.TabIndex = 5;
- this.pictureBox6.TabStop = false;
- this.pictureBox6.Visible = false;
- //
- // pictureBox7
- //
- this.pictureBox7.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox7.Image")));
- this.pictureBox7.Location = new System.Drawing.Point(8, 8);
- this.pictureBox7.Name = "pictureBox7";
- this.pictureBox7.Size = new System.Drawing.Size(16, 16);
- this.pictureBox7.TabIndex = 6;
- this.pictureBox7.TabStop = false;
- this.pictureBox7.Visible = false;
- //
- // pictureBox9
- //
- this.pictureBox9.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox9.Image")));
- this.pictureBox9.Location = new System.Drawing.Point(56, 8);
- this.pictureBox9.Name = "pictureBox9";
- this.pictureBox9.Size = new System.Drawing.Size(16, 16);
- this.pictureBox9.TabIndex = 8;
- this.pictureBox9.TabStop = false;
- this.pictureBox9.Visible = false;
- //
- // Dice
- //
- this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
- this.Controls.Add(this.pictureBox9);
- this.Controls.Add(this.pictureBox7);
- this.Controls.Add(this.pictureBox6);
- this.Controls.Add(this.pictureBox5);
- this.Controls.Add(this.pictureBox4);
- this.Controls.Add(this.pictureBox3);
- this.Controls.Add(this.pictureBox1);
- this.Name = "Dice";
- this.Size = new System.Drawing.Size(80, 80);
- this.DoubleClick += new System.EventHandler(this.Dice_DoubleClick);
- this.ResumeLayout(false);
- }
-
- private void Dice_DoubleClick(object sender, System.EventArgs e)
- {
- active=!active;
- }
-
- #endregion
- }
- }
-